using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace SharpMud.Server.Systems.Net.Intermud3
{
    [XmlRoot("I3SystemConfiguration")]
    public class I3SystemConfiguration
    {
        private const string OOB_SLU_Protocol = "i3oob";
        private SLU _OOB_ListenOn;
        private int _DefaultRestartTime;
        private string _RouterUriString;
        private string _MudName;

        public I3SystemConfiguration()
        {
        }

        /// <summary>
        /// The SLU string used to designate at which (relative) port to listen for OOB connections on
        /// </summary>
        [XmlElement("OOB_ListenOn")]
        public SLU OOB_ListenOn
        {
            get
            {
                if (_OOB_ListenOn != null)
                {
                    if (_OOB_ListenOn.ProtocolDesignation != OOB_SLU_Protocol)
                        _OOB_ListenOn.ProtocolDesignation = OOB_SLU_Protocol;
                }
                return _OOB_ListenOn;
            }
            set
            {
                _OOB_ListenOn = value;
                if (_OOB_ListenOn != null)
                {
                    if (_OOB_ListenOn.ProtocolDesignation != OOB_SLU_Protocol)
                        _OOB_ListenOn.ProtocolDesignation = OOB_SLU_Protocol;
                }                
            }
        }

        /// <summary>
        /// In an emergency shutdown of the I3 system, this is the amount of time by default
        /// to tell the router that we will return in. This value will always be used if the IServerSystem
        /// handle is used to 'Stop' the I3System. To specify an explicit restart time on shutdown, use I3System's Shutdown() method.
        /// </summary>
        [XmlElement("DefaultRestartTime")]
        public int DefaultRestartTime
        {
            get
            {
                return _DefaultRestartTime;
            }
            set
            {
                _DefaultRestartTime = value;
            }
        }

        [XmlElement("RouterUri")]
        public string Router
        {
            get
            {
                return _RouterUriString;
            }
            set
            {
                _RouterUriString = value;
            }
        }

        [XmlElement("MudName")]
        private string MudName
        {
            get
            {
                return _MudName;
            }
            set
            {
                _MudName = value;
            }
        }

        [XmlIgnore()]
        public System.Uri RouterUri
        {
            get
            {
                return new Uri(_RouterUriString);
            }
            set
            {
                _RouterUriString = value.ToString();
            }
        }

    }
}
